package com.xiaoshuidi.cloud.module.rooms.convert.roomel;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.*;
import com.xiaoshuidi.cloud.module.rooms.pojo.roomel.MyGeoEntity;
import com.xiaoshuidi.cloud.module.rooms.pojo.roomel.RoomelEntity;
import jodd.util.StringUtil;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Convert
 *
 * @author
 */
@Mapper
public interface RoomelConvert {

    RoomelConvert INSTANCE = Mappers.getMapper(RoomelConvert.class);

    @Mapping(source = ".", target = "apartmentAreaGeo", qualifiedByName = "latlonToApartmentAreaGeo")
    @Mapping(source = ".", target = "apartmentGeo", qualifiedByName = "latlonToApartmentGeo")
    RoomelEntity convert(RoomelCreateReqVO bean);

    @Mapping(source = ".", target = "apartmentAreaGeo", qualifiedByName = "latlonToApartmentAreaGeo")
    @Mapping(source = ".", target = "apartmentGeo", qualifiedByName = "latlonToApartmentGeo")
    RoomelEntity convert(RoomelUpdateReqVO bean);

    @Mapping(source = ".", target = "apartmentAreaGeo", qualifiedByName = "latlonToApartmentAreaGeo")
    @Mapping(source = ".", target = "apartmentGeo", qualifiedByName = "latlonToApartmentGeo")
    List<RoomelEntity> convertList(List<RoomelCreateReqVO> list);

    //实体类转vo
    List<RoomelEntity> convertList4(List<RoomelUpdateReqVO> bean);

    @Mapping(source = "apartmentAreaGeo", target = "apartmentAreaLat", qualifiedByName = "geoTolat")
    @Mapping(source = "apartmentAreaGeo", target = "apartmentAreaLon", qualifiedByName = "geoTolon")
    RoomelQueryResp convert(RoomelEntity bean);

    List<RoomelQueryResp> convertList3(List<RoomelEntity> list);


// 定制化转换方法------------------------------------------------------------------------
//    方法：经纬度转换
    @Named("latlonToApartmentAreaGeo")
    static String latlonToApartmentAreaGeo(RoomelBaseVo source){
        if(ObjectUtil.isAllNotEmpty(source.getApartmentAreaLat(), source.getApartmentAreaLon())){
            String geo = source.getApartmentAreaLat() + "," + source.getApartmentAreaLon();
            return geo;
        }
        return null;
    }
    @Named("latlonToApartmentGeo")
    static String latlonToApartmentGeo(RoomelBaseVo source){
        if(ObjectUtil.isAllNotEmpty(source.getApartmentLat(), source.getApartmentLon())){
            String geo = source.getApartmentLat() + "," + source.getApartmentLon();
            return geo;
        }
        return null;
    }
    @Named("geoTolat")
    static String geoTolat(String geo){
        if(ObjectUtil.isEmpty(geo)){
            return "";
        }
        return geo.split(",")[0];
    }
    @Named("geoTolon")
    static String geoTolon(String geo){
        if(ObjectUtil.isEmpty(geo)){
            return "";
        }
        return geo.split(",")[1];
    }

}
